<template>
	<view class="problemPage">
		<view class="card">
			<textarea v-model="txt" class="txt" name="" placeholder="请输入(必填)"></textarea>
		</view>
		<view class="pic">
			<u-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" multiple width="240rpx" name="1"
				height="240rpx">
				<view class="add-img">
					<u-icon name="plus" color="#ABABAB" size="32"></u-icon>
				</view>
			</u-upload>
		</view>
		<button @click="submit" class="sned_btn">提交</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				fileServer: this.$fileServer,
				fileList1: [],
				txt:'',
			};
		},
		onLoad(options) {
			
		},
		methods: {
			// send
			submit(){
				// path
				if(!this.txt){
					uni.showToast({
						title: '请输入反馈内容',
						icon: "none"
					})
					return false
				}
				var imgList = this.fileList1.map(ele=>ele.path)
				let img = imgList.join(',')
				this.$api.msg.saveWtfk({content:this.txt,img}).then(res => {
					uni.showToast({
						title: res.msg,
						icon: "none"
					})
					if(res.flag){
						uni.navigateBack()
					}
				})
			},
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: this.$fileServer + result,
						path: result
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: this.$serverUrl + '/api/member/uploadFile.client', //仅为示例，非真实的接口地址
						filePath: url,
						name: 'upload',
						success: (uploadFileRes) => {
							resolve(JSON.parse(uploadFileRes.data).data)
						}
					});
				})
			},
		},
		
	}
</script>

<style lang="scss" scoped>
	.problemPage {background-color: #F8F9FA;min-height: 100vh;padding: 18rpx 28rpx;
		.card{padding:24rpx;border-radius: 15rpx;background-color: #fff;
			.txt{width: 100%;height: 150rpx;font-size:30rpx;lien-height:40rpx;}
		}
		.pic{margin-top: 30rpx;
			.add-img{width: 240rpx;height: 240rpx;border-radius: 20rpx;background-color: #EDEDED;
				display: flex;align-items: center;justify-content: space-around;
			}
		}
		.sned_btn{position: fixed;left:0;right:0;bottom:30rpx;margin:auto;width: 644rpx;height: 94rpx;line-height: 94rpx;background: #EC2424;border-radius: 47rpx;color: #FFFFFF;font-size: 32rpx;text-align: center;}
			
	}
</style>